package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.VipSettingMapper;
import com.lanyan.system.domain.VipSetting;
import com.lanyan.system.domain.vo.VipSettingVo;
import com.lanyan.system.service.IVipSettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * vip设置Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class VipSettingServiceImpl  extends ServiceImpl<VipSettingMapper,VipSetting> implements IVipSettingService

{
    @Autowired
    private VipSettingMapper vipSettingMapper;

    /**
     * 查询vip设置
     *
     * @param vipSettingId vip设置主键
     * @return vip设置
     */
    @Override
    public VipSetting selectVipSettingByVipSettingId(Long vipSettingId)
    {
        return this.getById(vipSettingId);
    }

    /**
     * 查询vip设置Vo列表
     *
     * @param vipSetting vip设置
     * @return vip设置
     */
    @Override
    public List<VipSettingVo> selectVipSettingVoList(VipSetting vipSetting)
    {
        return selectVipSettingList(vipSetting)
                .stream()
                .map(x -> (VipSettingVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询vip设置列表
     *
     * @param vipSetting vip设置
     * @return vip设置
     */
    @Override
    public List<VipSetting> selectVipSettingList(VipSetting vipSetting)
    {
        LambdaQueryChainWrapper<VipSetting> wrapper = this.lambdaQuery().eq(VipSetting::getDelFlag,"0");
        if (StringUtils.isNotEmpty(vipSetting.getName())) {
            wrapper.like(VipSetting::getName, vipSetting.getName());
        }
        if (vipSetting.getPrice() != null) {
            wrapper.eq(VipSetting::getPrice, vipSetting.getPrice());
        }
        if (vipSetting.getTimer() != null) {
            wrapper.eq(VipSetting::getTimer, vipSetting.getTimer());
        }
        return wrapper.list();
    }

        /**
         * 新增vip设置
         *
         * @param vipSetting vip设置
         * @return 结果
         */
    @Override
        public boolean insertVipSetting(VipSetting vipSetting)
        {
                    vipSetting.setCreateTime(DateUtils.getNowDate());
                return this.save(vipSetting);
        }

        /**
         * 修改vip设置
         *
         * @param vipSetting vip设置
         * @return 结果
         */
    @Override
        public boolean updateVipSetting(VipSetting vipSetting)
        {
                    vipSetting.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(vipSetting);
        }

        /**
         * 批量删除vip设置
         *
         * @param vipSettingIds 需要删除的vip设置主键
         * @return 结果
         */
    @Override
        public boolean deleteVipSettingByVipSettingIds(Long[] vipSettingIds)
        {
            return this.lambdaUpdate().set(VipSetting::getDelFlag,"1").in(VipSetting::getVipSettingId,vipSettingIds).update();
        }

        /**
         * 删除vip设置信息
         *
         * @param vipSettingId vip设置主键
         * @return 结果
         */
    @Override
        public boolean deleteVipSettingByVipSettingId(Long vipSettingId)
        {
            return this.lambdaUpdate().set(VipSetting::getDelFlag,"1").eq(VipSetting::getVipSettingId,vipSettingId).update();
        }
    }
